home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak Vol C-14
/
Vol C-14.iso
/
games
/
kayak.swf
/
scripts
/
frame_2
/
DoAction.as
Wrap
Text File
|
2012-04-23
|
3KB
|
146 lines
function initGame()
{
firstRock = 1;
lastRock = 0;
spills = 0;
timeSinceLastRock = 0;
riverSpeed = 0;
startTime = getTimer();
riverPos = 0;
attachMovie("kayaking fox","fox",999999);
fox._x = 275;
fox._y = 200;
}
function moveFox()
{
if(4 < fox._currentFrame)
{
dx = 0;
}
else if(Key.isDown(Key.RIGHT))
{
if(10 < riverSpeed)
{
riverSpeed -= 1;
}
dx = riverSpeed;
fox.gotoAndStop("left");
}
else if(Key.isDown(Key.LEFT))
{
if(10 < riverSpeed)
{
riverSpeed -= 1;
}
dx = - riverSpeed;
fox.gotoAndStop("right");
}
else
{
dx = 0;
fox.gotoAndStop("still");
}
fox._x += dx;
if(fox._x < 150)
{
fox._x = 150;
}
if(400 < fox._x)
{
fox._x = 400;
}
if(riverSpeed < 25)
{
riverSpeed += 0.5;
}
riverPos += riverSpeed;
showGameTime();
if(riverPos >= 30000)
{
removeAll();
gotoAndPlay(4);
}
}
function newRock()
{
if(5 < timeSinceLastRock)
{
if(Math.random() < 0.25)
{
lastRock++;
attachMovie("rocks","rock" + lastRock,lastRock);
_root["rock" + lastRock]._x = Math.random() * 250 + 150;
_root["rock" + lastRock]._y = 450;
f = int(Math.Random() * _root["rock" + lastRock]._totalFrames) + 1;
_root["rock" + lastRock].gotoAndStop(f);
timeSinceLastRock = 0;
_root["rock" + i].hit = false;
}
}
timeSinceLastRock++;
}
function moveRocks()
{
side1._y -= riverSpeed;
if(side1._y < -400)
{
side1._y += 400;
}
side2._y -= riverSpeed;
if(side2._y < -200)
{
side2._y += 400;
}
i = firstRock;
while(lastRock >= i)
{
x = _root["rock" + i]._x;
y = _root["rock" + i]._y - riverSpeed;
if(y < -50)
{
removeRock(i);
}
else if(_root["rock" + i].hit == false and Math.abs(y - fox._y) < 60 and Math.abs(x - fox._x) < 25)
{
spills += 1;
_root["rock" + i].hit = true;
fox.gotoAndPlay("spill");
riverSpeed = 0;
if(5 < spills)
{
removeAll();
gotoAndPlay(3);
}
}
_root["rock" + i]._y = y;
i++;
}
}
function removeRock(n)
{
_root["rock" + n].removeMovieClip();
firstRock = n + 1;
}
function removeAll()
{
i = firstRock;
while(lastRock >= i)
{
_root["rock" + i].removeMovieClip();
i++;
}
fox.removeMovieClip();
}
function showGameTime()
{
gametime = int((getTimer() - startTime) / 1000);
if(gametime != lasttime)
{
lasttime = gametime;
mins = int(gametime / 60);
secs = gametime - mins * 60;
showtime = mins + ":" + String(100 + secs).substr(1,2);
}
}
stop();